from django import forms
from .models import Product,Job,Suite,Step

REQUESTMETHODS = (
        ('GET', 'GET'),
        ('POST', 'POST'),
    )
OPERATIONS = (
        ('OpenBrowser','打开浏览器'),
        ('Click','点击'),
        ('Type','输入'),
        ('Check','检查'),
        ('CloseBrowser','关闭浏览器'),
    )
LOCATEMETHODS = (
        ('XPATH','XPATH'),
        ('ID','ID'),
        ('NAME','NAME'),
    )

class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = ['id','name','member','member_leader','participant','participant_leader','description']
        labels = {'id':'','name':'产品名称','member':'开发成员','member_leader':'开发负责人','participant':'测试成员','participant_leader':'测试负责人','description':'描述'}


class JobForm(forms.ModelForm):
    class Meta:
        model = Job
        fields = ['name','product','description']
        labels = {'name':'Job名称','product':'所属产品','description':'描述'}



class SuiteForm(forms.ModelForm):
    class Meta:
        model = Suite
        fields = ['id','name','description','job','creater','type']
        labels = {'id':'','name':'测试套件名称','job':'所属job','creater':'创建者','description':'测试套件描述','type':'套件类型'}


class APIStepForm(forms.ModelForm):

    #id = forms.IntegerField(label='',required=False)
    api_url = forms.CharField(label='接口地址',required=True)
    api_json = forms.CharField(label='请求json',required=False)
    api_method = forms.CharField(label='请求方法',widget=forms.Select(choices=REQUESTMETHODS))
    api_header = forms.CharField(label='请求头',required=False)
    api_params=forms.CharField(label='请求参数',required=False)
    api_expect =forms.CharField(label='期望结果',required=True)
    #result = forms.CharField(label='执行结果',required=False)

    class Meta:
        model = Step
        fields = [
            #'id',
            'api_url',
            'api_json',
            'api_method',
            'api_header',
            'api_params',
            'api_expect',
            #'result',
        ]

class UIStepForm(forms.ModelForm):
    ui_operation = forms.CharField(label='操作',widget=forms.Select(choices=OPERATIONS))
    ui_locate_method = forms.CharField(label='定位方式',widget=forms.Select(choices=LOCATEMETHODS))
    ui_locate_url = forms.CharField(label='定位表达式',required=False)
    ui_data = forms.CharField(label='操作数据',required=False)
    #result = forms.CharField(label='执行结果',required=False)
    class Meta:
        model = Step
        fields = [
            #'id',
            'ui_operation',
            'ui_locate_method',
            'ui_locate_url',
            'ui_data',
            #'result',
        ]